# -*- coding: utf-8 -*-

#----------------------------------------------------------------------
# A palindromic number reads the same both ways. The largest palindrome made from 
# the product of two 2-digit numbers is 9009 = 91 × 99.
# Find the largest palindrome made from the product of two 3-digit numbers.
#
# 求由两个三位数相乘得到的最大回文数。

from string import *
from count_exec_time import *

def prob4():
    print 'Totla elapsed time is: ' + str(pytime(resolver, (), {}, 10.0))

def resolver():
    result = 0
    for i in range(100, 999):
        for j in range(i, 999):            
            if isPalindromicNumber(i * j):
                tmp = i * j
                if tmp > result:
                    result = tmp
    print 'The palindromic number is: ' + str(result)
    
#
# judge a number is palindromic number or not.
#    
def isPalindromicNumber(num):    
    if not str(num).isdigit():
        return False
    
    tmp = num
    pn = 0
    while tmp:
        pn = pn * 10 + tmp % 10
        tmp /= 10
    
    if pn == num:
        return True
    
    return False


# invoke to compute.    
prob4();
